package org.td.engine.map;

import com.badlogic.gdx.graphics.OrthographicCamera;

public class MapCamera extends OrthographicCamera {

    private int width;
    private int height;

    private int boundsX;
    private int boundsY;

    private int x;
    private int y;

    public MapCamera(int boundsX, int boundsY, int width, int height) {
        this.width = width;
        this.height = height;
        this.boundsX = boundsX;
        this.boundsY = boundsY;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setPosition(int x, int y) {
        this.x = x;
        this.y = y;
        checkBounds();
        position.set(width / 2 + this.x, height / 2 + this.y, 0);
    }

    public void addPosition(int x, int y) {
        setPosition(this.x + x, this.y + y);
    }

    private void checkBounds() {
        if (x < 0) {
            x = 0;
        } else if (x > boundsX - width) {
            x = boundsX - width;
        }

        if (y < 0) {
            y = 0;
        } else if (y > boundsY - height) {
            y = boundsY - height;
        }
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int toWorldX(int x) {
        return x + this.x;
    }

    public int toWorldY(int y) {
        return y + this.y;
    }


}
